package com.ben.notebook.infrastructure.mapper;

import com.ben.notebook.domain.Note;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface NoteMapper {

    @Select("select * from note where status != #{status}")
    @Results({
            @Result(property = "noteId",column = "note_id"),
            @Result(property = "createTime",column = "create_time"),
            @Result(property = "modifyTime",column = "modify_time")
    })
    List<Note> getAllWithoutDel(char status);

    @Select("select * from note where status != #{s} and (status=#{note.status} or title=#{note.title} or content=#{note.content})")
    @Results({
            @Result(property = "noteId",column = "note_id"),
            @Result(property = "createTime",column = "create_time"),
            @Result(property = "modifyTime",column = "modify_time")
    })
    List<Note> getFilterList(@Param(value = "note") Note note,@Param(value = "s") char status);

    @Update("update note set title=#{title},content=#{content},modify_time=#{modifyTime} where note_id=#{noteId}")
    int update(Note note);

    @Insert("insert into note(title,content,status,create_time) " +
            "values (#{title},#{content},#{status},#{createTime})")
    int create(Note note);

    @Delete("update note set status=#{status} where note_id=#{noteId}")
    int deleteByChangeStatus(Note note);
}
